package com.apo1o.cmscore.service.impl;

import com.apo1o.cmscore.bean.User;
import com.apo1o.cmscore.bean.ext.UserExt;
import com.apo1o.cmscore.dao.UserDao;
import com.apo1o.cmscore.exception.ServiceException;
import com.apo1o.cmscore.service.IUserService;
import com.apo1o.cmscore.util.ResultCode;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Apo1o
 * @since 2023-11-15
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements IUserService {
    @Autowired UserDao userDao;
    @Override
    public IPage<UserExt> query(Integer pageNum, Integer pageSize, String username, String status, Integer roleId, Integer isVip) {
        if (pageNum == null || pageSize == null)
            throw new ServiceException(ResultCode.PARAM_IS_BLANK);

        //关键点：程序员自行书写sql语句，要完成多表连接查询，如何进行分页处理？ 推荐下面写法


        IPage<UserExt> page = new Page<>(pageNum, pageSize);
        userDao.queryAllUserWithRole(page, username, status, roleId, isVip);
            return page;
    }
    }
